<template>
  <!-- 审核人员确认预警处置对话框 -->
  <div>
    <el-dialog :title="title" :visible.sync="dialogOpen" :before-close="cancel" width="550px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px" :disabled="disabled">
        <el-form-item label="处置说明" prop="disposalInstructions">
          <el-input type="textarea" v-model="form.disposalInstructions" placeholder="请输入处置说明" />
        </el-form-item>
        <el-form-item label="图片" prop="imgUrl"><imageUpload v-model="form.imgUrl" /></el-form-item>
        <el-form-item label="附件" prop="fileUrl"><fileUpload v-model="form.fileUrl" /></el-form-item>
      </el-form>
      <el-divider></el-divider>
      <el-form ref="form" :model="form" :disabled="detailsDisabled" label-width="80px">
        <el-form-item label="审批意见" prop="approvalOpinions">
          <el-input type="textarea" v-model="form.approvalOpinions" placeholder="" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="danger" @click="handleApproval(0)" v-if="!detailsDisabled" :disabled="detailsDisabled">驳  回</el-button>
        <el-button :loading="buttonLoading" type="primary" @click="handleApproval(1)" v-if="!detailsDisabled" :disabled="detailsDisabled">同  意</el-button>
        <el-button @click="cancel" v-if="detailsDisabled" type="primary">确  定</el-button>
        <el-button @click="cancel" v-else>取  消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getInfoByWarningId, handleApproval } from "@/api/zhgd/nWarningHnt";
export default {
  name:"DisposalConfirm.vue",
  props:['open'],
  data(){
    return{
      // 遮罩层
      loading: true,
      buttonLoading:false,
      title:"title",
      form:{
        approvalOpinions:'',
        disposalInstructions:'',
        imgUrl:'',
        fileUrl:'',
        warningId: null,
        warningType: null
      },
      dialogOpen:false,
      disabled:false,
      detailsDisabled:false,
      // 列信息
      // 日期范围
      // 选中数组
      ids: [],
    }
  },
  mounted(){
    this.dialogOpen = this.open;
    // // 根据业务id请求对应接口获取数据回显表单
    // if (!!this.form.warningId) {
    //   getInfoByWarningId(this.form.warningId,this.form.warningType).then(res => {
    //     console.log('res',res)
    //     this.form = res
    //     this.form.approvalOpinions = ''
    //   }).catch(error =>{})
    // } else {
    //   this.form.approvalOpinions = ''
    // }
  },

  created() {
  },

  methods:{

    getInfoByWarningId(){
      if (!!this.form.warningId) {
        getInfoByWarningId(this.form.warningId,this.form.warningType).then(res => {
          this.form = res.data?res.data:this.form
          this.form.approvalOpinions = ''
          if (!this.dialogOpen) {
            this.dialogOpen = true
          }
        }).catch(error =>{})
      } else {
        this.form.approvalOpinions = ''
      }
    },
    details(){
      if (!!this.form.warningId) {
        getInfoByWarningId(this.form.warningId,this.form.warningType).then(res => {
          this.form = res.data?res.data:this.form
          if (!this.dialogOpen) {
            this.dialogOpen = true
          }
        }).catch(error =>{})
      } else {
      }
    },
    // 取消
    cancel(){
      this.dialogOpen = false;
      this.form.approvalOpinions = ''
      this.$emit('closeDialog')
    },
    //  0驳回1同意
    handleApproval (status) {
      // 参数
      console.log('form----------------', this.form)
      // 驳回
      const params = {...this.form}
      if (status == 0) {
        params.status = 5
      }
      // 同意
      if (status == 1) {
        params.status = 4
      }
      handleApproval(params).then(res => {
        console.log('res;;;_______',JSON.stringify(res))
        this.$emit('getList')
        this.cancel()
        this.$message.success("操作成功")
      }).catch(error =>{})
    },
  }
}
</script>

<style>

</style>
